/*
Copyright (c) 2009 Hayden Curran <haydenz@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
        this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
        this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.
    * The names of its contributors may not be used to endorse or promote
        products derived from this software without specific prior
        written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef _IRC_H
#define _IRC_H

#ifdef WIN32
    #define WINVER 0x0501   // Ew, hax for getaddrinfo

    #include <winsock2.h>
    #include <ws2tcpip.h>
#else
    // Add Linux includes here
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "buffer.h"
#include "pug.h"

#define IRC_SERVER "irc.gamesurge.net"
#define IRC_PORT "6667"
#define IRC_NICK "OkonkPug"
#define IRC_CHAN "#OkonkPugBot"

void irc_init(buffer_t *irc_buffer, pug_t *pug);
/*
    Sets up a socket and connects to the specified IRC server
    Sends the specified nickname
    Returns the socket descriptor
*/
int irc_connect(void);
/*
    Handles recv on ircfd
*/
int irc_receive(int ircfd, buffer_t *irc_buffer, pug_t *pug);
/*
    Sends null terminated string, buf to ircfd
    Returns the characters sent
*/
int irc_send(int ircfd, char *buf);
/*
    Called when we received a PRIVMSG from the channel.
*/
int irc_process_chan_msg(int ircfd, char **servtoks, char **argtoks,
    buffer_t *irc_buffer, pug_t *pug);
/*
    Called when a pug is created
    Sets the channel topic, announces to the channel.
    Asks the captain for server details and rcon.
*/
int irc_msg_pug_created(int ircfd, pug_t *pug);
/*
    Called when someone joins the pug
    Messages the channel they successfully joined and the new player count.
*/
int irc_msg_pug_join(int ircfd, pug_t *pug, char *name);
/*
    Called when we have enough players but don't have a server to use
*/
int irc_msg_pug_need_server(int ircfd, pug_t *pug);
/*
    Called when we have enough players and a server
*/
int irc_msg_pug_vote_start(int ircfd, pug_t *pug);
/*
    When someone leaves the pug, either by parting, quitting or by !l
*/
int irc_pug_leave(int ircfd, pug_t *pug, char *name);
/*
    Called when someone leaves the pug
*/
int irc_msg_pug_leave(int ircfd, pug_t *pug, char *name);
/*
    Everyone left the pug
*/
int irc_msg_pug_disbanded(int ircfd, pug_t *pug);
/*
    Old captain left so new one assigned
*/
int irc_msg_pug_new_captain(int ircfd, pug_t *pug);
/*
    player voted on a map
*/
int irc_msg_pug_map_vote(int ircfd, pug_t *pug, char *player);
/*
    Called when voting is finished, either by everyone voting or
    by a timer
*/
int irc_pug_voting_finished(int ircfd, pug_t *pug);
/*
    Messages the channel when voting is finished
*/
int irc_msg_pug_voting_finished(int ircfd, pug_t *pug);
/*
    Private messages everyone in the PUG the server details
*/
int irc_msg_pug_server_details(int ircfd, pug_t *pug);
/*
    Messages the channel the current players
*/
int irc_msg_pug_player_list(int ircfd, pug_t *pug);
/*
    Messages the channel no pug started
*/
int irc_msg_no_pug_started(int ircfd, pug_t *pug);

#endif // _IRC_H
